package com.vancouver.knows.business.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.pangu.util.StringUtil;
import com.vancouver.knows.business.bean.UserPostInfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by Chris Li on 2016-07-22.
 */
public class GetUserPostsHandler extends ACheckableJsonParser {

    public static final String KEY_USER_POSTS = "userpost_array";

    private HashMap<String, Object> resultMap = new HashMap<String, Object>();

    @Override
    protected void parserContent(JSONObject content) throws Exception {

        String posts = content.getString(KEY_USER_POSTS);
        if (StringUtil.isEmptyString(posts)) {
            resultMap.put(KEY_USER_POSTS, new ArrayList<UserPostInfo>());
        } else {
            List<UserPostInfo> userPostInfoList = JSON.parseArray(posts, UserPostInfo.class);
            resultMap.put(KEY_USER_POSTS, userPostInfoList);
        }
    }

    public HashMap<String, Object> getResultMap() {
        return resultMap;
    }

}
